<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组操作</title>
</head>
<body>
<div id="lastData"></div>
<div id="newData"></div>
</body>
<script type="text/javascript">
    /**
     * @Description:
     * @author 朱志文
     * @date 2021/9/24
     */
    /*创建数组*/
    var arr = [1, 2, 3, 4, 2, 5, 6, 2, 7, 2]
    var arr1 = [];
    // document.write('原数组:')
    lastData = '<div>' + "原数组: ";
    for (let i = 0; i < arr.length; i++) {
        lastData += `<span>` + arr[i] + ', ' + `</span>`
        // document.write(' '+arr[i]+',')
        /*判断数组数值是否为二，不为2的传入新数组*/
        if (arr[i] != 2) {
            arr1.push(arr[i])

        }
    }
    lastData += `</div>`
    /*打印新数组*/
    newData = `<div>` + '新数组: ';
    // document.write(`<br>`+'新数组: ')
    for (let j = 0; j < arr1.length; j++) {
        newData += `<span>` + arr1[j] + ', ' + `</span>`
        // document.write(' '+arr1[j]+',')
    }
    document.getElementById("lastData").innerHTML = lastData;
    document.getElementById("newData").innerHTML = newData;
</script>
</html>